#!/bin/bash
RED_COLOR='\E[41m'
BLUE_COLOR='\E[44m'
RESET='\E[0m'
echo -e "${BLUE_COLOR}=== env check ===${RESET}"
if [ ! -e bochsrc ];then
    echo -e "${RED_COLOR}=== no bochsrc ===${RESET}"
    exit 1
fi

if [ ! -e /usr/local/bin/bochs ];then
    echo "${RED_COLOR}=== no bochs ===${RESET}"
    exit 1
fi

if [ ! -e /usr/local/bin/bximage ];then
    echo "${RED_COLOR}=== no bximage ===${RESET}"
    exit 1
fi

if [ -e boot.img ]; then
    rm boot.img
fi

echo -e "1\nfd\n\nboot.img\n" | bximage

# echo -e "${BLUE_COLOR}=== gen boot.bin ===${RESET}"
# cd bootloader
# make
# if [ $? -ne 0 ];then
#     echo -e "${RED_COLOR}=== bootloader make failed! ===${RESET}"
#     exit 1
# fi

# cd ..

# echo -e "${BLUE_COLOR}=== gen kernel.bin ===${RESET}"

# cd kernel
# make
# if [ $? -ne 0 ];then
#     echo -e "${RED_COLOR}=== kernel make failed! ===${RESET}"
#     exit 1
# fi

# cd ..

# echo -e "${BLUE_COLOR}=== write boot.bin to boot.img ===${RESET}"

# dd if=./boot/bootsect.bin of=boot.img bs=512 count=1 conv=notrunc
# mkdir media
# echo -e "${BLUE_COLOR}=== mount ===${RESET}"
# sudo mount -t vfat -o loop boot.img media/
# sudo cp boot/setup.bin media/
# sudo cp kernel/kernel.bin media/
# sync
# sudo umount media/
# rm -r media
# bochs -qf bochsrc
